package com.njdf.servlet;

import com.njdf.image.VerifyCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class VerifyCodeServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        VerifyCode verifyCode=new VerifyCode();
        //得到验证吗图片
        BufferedImage image =verifyCode.getImage();
        //得到验证码上的文本
        String text = verifyCode.getText();
        //放入session域中
        request.getSession().setAttribute("session_img",text);
        //响应图片输出流
        VerifyCode.output(image,response.getOutputStream());
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
